<?php
/**
 * @link https://ym2.cleverstone.top
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

use builder\helper\H5;
use yii\helpers\Json;

/* ================= 表单控件模板 ================= */

/** @var \yii\web\View $this View实例 */
/** @var array $controlItems 控件选项 */
/** @var string $requiredStyle 必填项标记风格 */
/** @var string $groupField 当前分组字段 */
?>
<?php foreach ($controlItems as $field => $control): ?>
<?php switch ($control['control']): case 'text': // text ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>">
    <?php if (!empty($control['label'])): ?>

        <label class="mb-1 label-color ym2-form-label" for="<?= $control['__id'] ?>">
            <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

                <sup class="layui-font-red">*</sup>
            <?php endif; ?>

            <?= $control['label'] ?>
            <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

                <span class="layui-font-gray f12">[ 选填 ]</span>
            <?php endif; ?>

            <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </label>
    <?php endif; ?>

    <!--text-->
    <input id="<?= $control['__id'] ?>"
           name="<?= $control['__id'] ?>"
           type="text"
           ng-model="<?= $control['__scope'] ?>"
           autocomplete="off"
           style="<?= $control['style'] ?>"
           placeholder="<?= $control['placeholder'] ?>"
           title="<?= $control['placeholder'] ?>"
           class="ym2-form-control layui-input layui-input-sm"<?= $control['attribute'] ?>>
</div>
<?php break; case 'datetime': //datetime/date/year/month/time ?>
<?php case 'date': //datetime/date/year/month/time ?>
<?php case 'year': //datetime/date/year/month/time ?>
<?php case 'month': //datetime/date/year/month/time ?>
<?php case 'time': //datetime/date/year/month/time ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>">
    <?php if (!empty($control['label'])): ?>

        <label class="mb-1 label-color ym2-form-label" for="<?= $control['__id'] ?>">
            <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

                <sup class="layui-font-red">*</sup>
            <?php endif; ?>

            <?= $control['label'] ?>
            <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

                <span class="layui-font-gray f12">[ 选填 ]</span>
            <?php endif; ?>

            <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </label>
    <?php endif; ?>

    <!--datetime/date/year/month/time-->
    <input id="<?= $control['__id'] ?>"
           name="<?= $control['__id'] ?>"
           type="text"
           ng-model="<?= $control['__scope'] ?>"
           ym2-laydate
           ym2-range="<?= $control['range'] ?>"
           ym2-type="<?= $control['control'] ?>"
           style="<?= $control['style'] ?>"
           placeholder="<?= $control['placeholder'] ?>"
           class="ym2-form-control layui-input layui-input-sm"
           title="<?= $control['placeholder'] ?>"
           autocomplete="off"
           readonly="readonly"<?= $control['attribute'] ?>>
</div>
<?php break; case 'select': // select ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>" style="<?= $control['style'] ?>">
    <?php if (!empty($control['label'])): ?>

        <label class="mb-1 label-color ym2-form-label" for="<?= $control['__id'] ?>">
            <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

                <sup class="layui-font-red">*</sup>
            <?php endif; ?>

            <?= $control['label'] ?>
            <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

                <span class="layui-font-gray f12">[ 选填 ]</span>
            <?php endif; ?>

            <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </label>
    <?php endif; ?>

    <!--select/select multiple-->
    <select name="<?= $control['__id'] ?>"
            id="<?= $control['__id'] ?>"
            ng-model="<?= $control['__scope'] ?>"
            ui-select2="<?= H5::encode(Json::encode($control['uiConfig'])) ?>"
            class="ym2-form-control invisible"
            data-placeholder="<?= $control['placeholder'] ?>"
            title="<?= $control['placeholder'] ?>"<?= !empty($control['multiple']) ? ' multiple' : '' ?><?= $control['attribute'] ?>>

            <?php if (empty($control['multiple'])): ?>

            <option value=""></option>
            <?php endif; ?>

            <?php foreach ($control['options'] as $value => $text): ?>
            <?php if (is_array($text)): ?>

                <optgroup label="<?= $value ?>">
                    <?php foreach ($text as $vv => $vTxt): ?>

                        <option <?= in_array($vv, $control['disabled']) ? 'disabled' : '' ?> value="<?= $vv ?>">
                            <?= $vTxt ?>
                        </option>
                    <?php endforeach; ?>

                </optgroup>
            <?php else: ?>

                <option <?= in_array($value, $control['disabled']) ? 'disabled' : '' ?> value="<?= $value ?>">
                    <?= $text ?>
                </option>
            <?php endif; ?>
            <?php endforeach; ?>

    </select>
</div>
<?php break; case 'select_link': //select link ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>" style="<?= $control['style'] ?>">
    <?php if (!empty($control['label'])): ?>

        <label class="mb-1 label-color ym2-form-label" for="<?= $control['__id'] ?>">
            <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

                <sup class="layui-font-red">*</sup>
            <?php endif; ?>

            <?= $control['label'] ?>
            <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

                <span class="layui-font-gray f12">[ 选填 ]</span>
            <?php endif; ?>

            <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </label>
    <?php endif; ?>
    <?php if (!empty($control['options'])): // start ?>

        <select ui-select2="<?= H5::encode(Json::encode($control['uiConfig'])) ?>"
                class="invisible"
                id="<?= $control['__id'] ?>"
                name="<?= $control['__id'] ?>"
                ng-change="callSelectLink('<?= $groupField ?>', '<?= $field ?>', <?= H5::encode(Json::encode($control["targetLink"])) ?>, '<?= H5::encode($control["route"]) ?>')"
                ng-model="<?= $control['__scope'] ?>"
                title="<?= $control['placeholder'] ?>"
                data-placeholder="<?= $control['placeholder'] ?>"<?= $control['attribute'] ?>>

            <option value=""><?= $control['placeholder'] ?></option>
                <?php foreach ($control['options'] as $value => $text): ?>
                <?php if (is_array($text)): ?>

                    <optgroup label="<?= $value ?>">
                        <?php foreach ($text as $vv => $vTxt): ?>

                            <option <?= in_array($vv, $control['disabled']) ? 'disabled' : '' ?> value="<?= $vv ?>">
                                <?= $vTxt ?>
                            </option>
                        <?php endforeach; ?>

                    </optgroup>
                <?php else: ?>

                    <option <?= in_array($value, $control['disabled']) ? 'disabled' : '' ?> value="<?= $value ?>">
                        <?= $text ?>
                    </option>
                <?php endif; ?>
                <?php endforeach; ?>

        </select>
    <?php elseif (!empty($control["targetLink"])): // through ?>

        <select ui-select2="<?= H5::encode(Json::encode($control['uiConfig'])) ?>"
                class="invisible"
                id="<?= $control['__id'] ?>"
                name="<?= $control['__id'] ?>"
                ng-change="callSelectLink('<?= $groupField ?>', '<?= $field ?>', <?= H5::encode(Json::encode($control["targetLink"])) ?>, '<?= H5::encode($control["route"]) ?>')"
                ng-model="<?= $control['__scope'] ?>"
                title="<?= $control['placeholder'] ?>"
                data-placeholder="<?= $control['placeholder'] ?>"<?= $control['attribute'] ?>>

            <option value=""><?= $control['placeholder'] ?></option>
            <optgroup ng-if="!<?= $groupField . '__' . $field ?>__options.length"
                      label="{{index}}"
                      ng-repeat="(index, item) in <?= $groupField . '__' . $field ?>__options">
                <option ng-repeat="son in item"
                        value="{{son.value}}"
                        ng-disabled="son.disabled"
                        ng-bind-html="son.text | toHtml">
                </option>
            </optgroup>
            <option ng-if="<?= $groupField . '__' . $field ?>__options.length"
                    ng-repeat="item in <?= $groupField . '__' . $field ?>__options"
                    value="{{item.value}}"
                    ng-disabled="item.disabled"
                    ng-bind-html="item.text | toHtml">
            </option>
        </select>
    <?php else: // end ?>

        <select ui-select2="<?= H5::encode(Json::encode($control['uiConfig'])) ?>"
                class="invisible"
                id="<?= $control['__id'] ?>"
                name="<?= $control['__id'] ?>"
                ng-model="<?= $control['__scope'] ?>"
                title="<?= $control['placeholder'] ?>"
                data-placeholder="<?= $control['placeholder'] ?>"<?= $control['attribute'] ?>>

            <option value=""><?= $control['placeholder'] ?></option>
            <optgroup ng-if="!<?= $groupField . '__' . $field ?>__options.length"
                      label="{{index}}"
                      ng-repeat="(index, item) in <?= $groupField . '__' . $field ?>__options">
                <option ng-repeat="son in item"
                        value="{{son.value}}"
                        ng-disabled="son.disabled"
                        ng-bind-html="son.text | toHtml">
                </option>
            </optgroup>
            <option ng-if="<?= $groupField . '__' . $field ?>__options.length"
                    ng-repeat="item in <?= $groupField . '__' . $field ?>__options"
                    value="{{item.value}}"
                    ng-disabled="item.disabled"
                    ng-bind-html="item.text | toHtml">
            </option>
        </select>
    <?php endif; ?>
</div>
<?php break; case 'number': //number ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>">
    <?php if (!empty($control['label'])): ?>

        <label class="mb-1 label-color ym2-form-label" for="<?= $control['__id'] ?>">
            <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

                <sup class="layui-font-red">*</sup>
            <?php endif; ?>

            <?= $control['label'] ?>
            <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

                <span class="layui-font-gray f12">[ 选填 ]</span>
            <?php endif; ?>

            <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </label>
    <?php endif; ?>

    <!--number-->
    <input id="<?= $control['__id'] ?>"
           name="<?= $control['__id'] ?>"
           type="number"
           ng-model="<?= $control['__scope'] ?>"
           string-to-number
           autocomplete="off"
           style="<?= $control['style'] ?>"
           class="ym2-form-control layui-input layui-input-sm"
           title="<?= $control['placeholder'] ?>"
           placeholder="<?= $control['placeholder'] ?>"<?= $control['attribute'] ?>>
</div>
<?php break; case 'textarea': //textarea ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>">
    <?php if (!empty($control['label'])): ?>

        <label class="mb-1 label-color ym2-form-label" for="<?= $control['__id'] ?>">
            <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

                <sup class="layui-font-red">*</sup>
            <?php endif; ?>

            <?= $control['label'] ?>
            <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

                <span class="layui-font-gray f12">[ 选填 ]</span>
            <?php endif; ?>

            <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </label>
    <?php endif; ?>

    <!--textarea-->
    <textarea name="<?= $control['__id'] ?>"
              id="<?= $control['__id'] ?>"
              ng-model="<?= $control['__scope'] ?>"
              rows="<?= $control['rows'] ?>"
              class="ym2-form-control layui-textarea"
              style="<?= $control['style'] ?>"
              title="<?= $control['placeholder'] ?>"
              placeholder="<?= $control['placeholder'] ?>"<?= $control['attribute'] ?>></textarea>
</div>
<?php break; case 'checkbox': // checkbox/tag ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>">
        <?php if (!empty($control['label'])): ?>

        <span class="mb-1 label-color ym2-form-label inline-block">
            <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

                <sup class="layui-font-red">*</sup>
            <?php endif; ?>

            <?= $control['label'] ?>
            <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

                <span class="layui-font-gray f12">[ 选填 ]</span>
            <?php endif; ?>

            <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </span>
        <?php endif; ?>

    <!--checkbox/tag-->
    <div class="layui-form" style="<?= $control['style'] ?>">
        <?php foreach ($control['options'] as $value => $text): ?>

            <input type="checkbox"
                   layui-form-render
                   lay-filter="ym2_form_checkbox"
                   ng-model="<?= $control['__scope'] ?>['<?= $value ?>']"
                   ng-true-value="1"
                   ng-false-value="0"
                   name="<?= $control['__id'] ?>[]"
                   title="<?= $text ?>"<?= $control['attribute'] ?>>
        <?php endforeach; ?>

    </div>
</div>
<?php break; case 'switch': //switch ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>">
        <?php if (!empty($control['label'])): ?>

        <span class="label-color ym2-form-label inline-block">
             <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

                 <sup class="layui-font-red">*</sup>
             <?php endif; ?>

             <?= $control['label'] ?>
             <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

                 <span class="layui-font-gray f12">[ 选填 ]</span>
             <?php endif; ?>

             <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </span>
        <?php endif; ?>

    <!--checkbox switch-->
    <div class="layui-form" style="<?= $control['style'] ?>">
        <input type="checkbox"
               layui-form-render
               lay-filter="ym2_form_switch"
               name="<?= $control['__id'] ?>"
               ng-model="<?= $control['__scope'] ?>"
               ng-true-value="1"
               ng-false-value="0"
               title="<?= $control['title'] ?>"
               lay-skin="switch"<?= $control['attribute'] ?>>
    </div>
</div>
<?php break; case 'hidden': //hidden ?>

<!--hidden-->
<input type="hidden" ng-model="<?= $control['__scope'] ?>">
<?php break; case 'password': //password ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>">
    <?php if (!empty($control['label'])): ?>

        <label class="mb-1 label-color ym2-form-label" for="<?= $control['__id'] ?>">
            <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

                <sup class="layui-font-red">*</sup>
            <?php endif; ?>

            <?= $control['label'] ?>
            <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

                <span class="layui-font-gray f12">[ 选填 ]</span>
            <?php endif; ?>

            <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </label>
    <?php endif; ?>

    <!--password-->
    <input id="<?= $control['__id'] ?>"
           name="<?= $control['__id'] ?>"
           type="password"
           ng-model="<?= $control['__scope'] ?>"
           autocomplete="off"
           style="<?= $control['style'] ?>"
           title="<?= $control['placeholder'] ?>"
           placeholder="<?= $control['placeholder'] ?>"
           class="ym2-form-control layui-input layui-input-sm"<?= $control['attribute'] ?>>
</div>
<?php break; case 'radio': //radio ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>">
        <?php if (!empty($control['label'])): ?>

        <span class="label-color ym2-form-label inline-block">
            <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

                <sup class="layui-font-red">*</sup>
            <?php endif; ?>

            <?= $control['label'] ?>
            <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

                <span class="layui-font-gray f12">[ 选填 ]</span>
            <?php endif; ?>

            <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </span>
        <?php endif; ?>

    <!--radio-->
    <div class="layui-form" style="<?= $control['style'] ?>">
        <?php foreach ($control['options'] as $value => $text): ?>

            <input type="radio"
                   layui-form-render
                   lay-filter="ym2_form_radio"
                   ng-model="<?= $control['__scope'] ?>"
                   value="<?= $value ?>"
                   name="<?= $control['__id'] ?>"
                   title="<?= $text ?>"<?= $control['attribute'] ?>>
        <?php endforeach; ?>

    </div>
</div>
<?php break; case 'range': //range ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>">
    <?php if (!empty($control['label'])): ?>

        <label class="mb-1 label-color ym2-form-label" for="<?= $control['__id'] ?>">
            <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

                <sup class="layui-font-red">*</sup>
            <?php endif; ?>

            <?= $control['label'] ?>
            <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

                <span class="layui-font-gray f12">[ 选填 ]</span>
            <?php endif; ?>

            <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </label>
    <?php endif; ?>

    <!--range-->
    <div class="d-flex align-items-center">
        <span ng-mousedown="triggerDecreaseStep('<?= $groupField ?>', '<?= $field ?>', <?= $control["step"] ?>, <?= $control["min"] ?>)"
              ng-mouseup="cancelStepperTimer()"
              class="bi bi-dash cursor-pointer border px-1 line-height15"></span>
        <input id="<?= $control['__id'] ?>"
               name="<?= $control['__id'] ?>"
               class="form-control-range cursor-pointer"
               string-to-number
               min="<?= $control['min'] ?>"
               max="<?= $control['max'] ?>"
               step="<?= $control['step'] ?>"
               title="{{ <?= $control['__scope'] ?> }}"
               ng-model="<?= $control['__scope'] ?>"
               type="range"
               style="<?= $control['style'] ?>"<?= $control['attribute'] ?>>
        <span ng-mousedown="triggerIncreaseStep('<?= $groupField ?>', '<?= $field ?>', <?= $control["step"] ?>, <?= $control["max"] ?>)"
              ng-mouseup="cancelStepperTimer()"
              class="bi bi-plus cursor-pointer border px-1 line-height15"></span>
    </div>
    <comment class="layui-font-primary">
        <?= $control['valueLabel'] ?>{{ <?= $control['__scope'] ?> }}<?= $control['valueUnit'] ?>
    </comment>
</div>
<?php break; case 'static_text': //静态文本 ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>">
        <?php if (!empty($control['label'])): ?>

        <span class="mb-1 label-color ym2-form-label inline-block">
            <?= $control['label'] ?>

            <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </span>
        <?php endif; ?>

    <!--static text-->
    <div class="py-1" style="<?= $control['style'] ?>"<?= $control['attribute'] ?> ng-bind-html="<?= $control['__scope'] ?> | toHtml"></div>
</div>
<?php break; case 'richtext': //富文本?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>">
        <?php if (!empty($control['label'])): ?>

        <span class="mb-1 label-color ym2-form-label inline-block">
            <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

                <sup class="layui-font-red">*</sup>
            <?php endif; ?>

            <?= $control['label'] ?>
            <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

                <span class="layui-font-gray f12">[ 选填 ]</span>
            <?php endif; ?>

            <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </span>
        <?php endif; ?>

    <!--richtext-->
    <div id="<?= $control['__id'] ?>" ym2-ueditor="<?= H5::encode($control['config']) ?>" style="<?= $control['style'] ?>"<?= $control['attribute'] ?>></div>
</div>
<?php break; case 'file': //文件上传 ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>">
        <?php if (!empty($control['label'])): ?>

        <span class="mb-1 label-color ym2-form-label inline-block">
            <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

                <sup class="layui-font-red">*</sup>
            <?php endif; ?>

            <?= $control['label'] ?>
            <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

                <span class="layui-font-gray f12">[ 选填 ]</span>
            <?php endif; ?>

            <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </span>
        <?php endif; ?>

    <!--file-->
    <div class="card border-0">
        <div ym2-upload="<?= H5::encode(Json::encode($control['scenario'])) ?>"
             ym2-style="<?= $control['style'] ?>"
             ym2-max="<?= $control['max'] ?>"
             ng-model="<?= $control['__scope'] ?>">
        </div>
    </div>
</div>
<?php break; case 'section': //控件区间 ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>">
        <?php if (!empty($control['label'])): ?>

        <span class="mb-1 label-color ym2-form-label inline-block">
            <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

                <sup class="layui-font-red">*</sup>
            <?php endif; ?>

            <?= $control['label'] ?>
            <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

                <span class="layui-font-gray f12">[ 选填 ]</span>
            <?php endif; ?>

            <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </span>
        <?php endif; ?>

    <!--section-->
    <div class="input-group">
        <input id="<?= $control['__id'] ?>_begin"
               type="text"
               autocomplete="off"
               ng-model="<?= $control['__scope'] ?>[0]"
               placeholder="<?= current($control['placeholder']) ?>"
               title="<?= current($control['placeholder']) ?>"
               style="<?= $control['firstStyle'] ?>"
               class="range1 ym2-form-control layui-input w-25 layui-input-sm"<?= $control['firstAttribute'] ?>>
        <span class="layui-font-gray px-2">-</span>
        <input id="<?= $control['__id'] ?>_end"
               type="text"
               autocomplete="off"
               ng-model="<?= $control['__scope'] ?>[1]"
               placeholder="<?= end($control['placeholder']) ?>"
               title="<?= end($control['placeholder']) ?>"
               style="<?= $control['lastStyle'] ?>"
               class="range2 ym2-form-control layui-input w-25 layui-input-sm"<?= $control['lastAttribute'] ?>>
    </div>
</div>
<?php break; case 'tag': //动态标签 ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>">
        <?php if (!empty($control['label'])): ?>

        <span class="mb-1 label-color ym2-form-label inline-block">
            <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

                <sup class="layui-font-red">*</sup>
            <?php endif; ?>

            <?= $control['label'] ?>
            <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

                <span class="layui-font-gray f12">[ 选填 ]</span>
            <?php endif; ?>

            <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </span>
        <?php endif; ?>

    <!-- active tag-->
    <div class="layui-btn-container tag"
         style="<?= $control['style'] ?>"
         id="<?= $control['__id'] ?>"
         lay-filter="<?= $control['__id'] ?>"
         lay-newTag="true"
         lay-allowclose="true"<?= $control['attribute'] ?>>
        <?php if (!empty($control['default']) && is_array($control['default'])): ?>
            <?php foreach ($control['default'] as $i => $content): ?>

                <button lay-id=""
                        lay-val="<?= H5::encode($content) ?>"
                        type="button"
                        class="tag-item layui-btn layui-btn-sm">
                    <?= H5::encode($content) ?>

                </button>
            <?php endforeach; ?>
        <?php endif; ?>

    </div>
</div>
<?php break; case 'trigger': //触发器 ?>
<div class="<?= $control['class'] ?>" style="<?= $control['style'] ?>"<?= $control['attribute'] ?><?= !empty($control['display']) ? " ng-show=\"{$control['__scope']}\"" : " ng-hide=\"{$control['__scope']}\"" ?>>

    <?= $this->renderPhpFile(
        __FILE__,
        [
            'controlItems' => $control['triggerItems'],
            'requiredStyle' => $requiredStyle,
            'groupField' => $groupField,
        ]) ?>

</div>
<?php break; case 'value_link': //值连接 ?>

    <?= $this->renderPhpFile(
            __FILE__,
            [
            'controlItems' => $control['sourceControl'],
            'requiredStyle' => $requiredStyle,
            'groupField' => $groupField,
        ]) ?>
<?php break; case 'dynamic_select': //动态下拉 ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>" style="<?= $control['style'] ?>">
    <?php if (!empty($control['label'])): ?>

        <label class="mb-1 label-color ym2-form-label" for="<?= $control['__id'] ?>">
            <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

                <sup class="layui-font-red">*</sup>
            <?php endif; ?>

            <?= $control['label'] ?>
            <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

                <span class="layui-font-gray f12">[ 选填 ]</span>
            <?php endif; ?>

            <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </label>
    <?php endif; ?>

    <div class="input-group">
        <?php if (!empty($control['btnPosition']['left'])): ?>

            <div class="input-group-prepend">
                <div class="layui-btn-group">
                    <?php foreach ($control['btnPosition']['left'] as $value): ?>
                    <?php switch ($value): case 'refreshBtn': //刷新 ?>

                        <!--刷新-->
                        <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" ng-click="actionDynamicSelectRefresh('<?= $control["__id"] ?>')">
                            <i class="bi bi-arrow-clockwise f15"></i>
                        </button>
                        <?php break; case 'additionBtn': //新增 ?>

                        <!--新增-->
                        <button type="button" class="layui-btn layui-btn-sm layui-btn-theme" ng-click="actionDynamicSelectAdd('<?= $control["__id"] ?>')">
                            <i class="bi bi-plus-circle f15"></i>
                        </button>
                    <?php break; endswitch; ?>
                    <?php endforeach; ?>

                </div>
            </div>
        <?php endif; ?>

        <!--select/select multiple-->
        <select name="<?= $control['__id'] ?>"
                id="<?= $control['__id'] ?>"
                ng-model="<?= $control['__scope'] ?>"
                ui-select2="<?= H5::encode(Json::encode($control['uiConfig'])) ?>"
                class="ym2-form-control invisible"
                data-placeholder="<?= $control['placeholder'] ?>"
                title="<?= $control['placeholder'] ?>"<?= !empty($control['multiple']) ? ' multiple' : '' ?><?= $control['attribute'] ?>>

            <?php if (empty($control['multiple'])): ?>

                <option value=""></option>
            <?php endif; ?>

            <optgroup ng-if="!<?= $control['__id'] ?>__options.length"
                      label="{{index}}"
                      ng-repeat="(index, item) in <?= $control['__id'] ?>__options">
                <option ng-repeat="children in item"
                        value="{{children.value}}"
                        ng-disabled="children.disabled"
                        ng-bind-html="children.text | toHtml">
                </option>
            </optgroup>
            <option ng-if="<?= $control['__id'] ?>__options.length"
                    ng-repeat="item in <?= $control['__id'] ?>__options"
                    value="{{item.value}}"
                    ng-disabled="item.disabled"
                    ng-bind-html="item.text | toHtml">
            </option>

        </select>
        <?php if (!empty($control['btnPosition']['right'])): ?>

            <div class="input-group-append">
                <div class="layui-btn-group">
                    <?php foreach ($control['btnPosition']['right'] as $value): ?>
                    <?php switch ($value): case 'refreshBtn': //刷新 ?>

                        <!--刷新-->
                        <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" ng-click="actionDynamicSelectRefresh('<?= $control["__id"] ?>')">
                            <i class="bi bi-arrow-clockwise f15"></i>
                        </button>
                    <?php break; case 'additionBtn': //新增 ?>

                        <!--新增-->
                        <button type="button" class="layui-btn layui-btn-sm layui-btn-theme" ng-click="actionDynamicSelectAdd('<?= $control["__id"] ?>')">
                            <i class="bi bi-plus-circle f15"></i>
                        </button>
                    <?php break; endswitch; ?>
                    <?php endforeach; ?>

                </div>
            </div>
        <?php endif; ?>

    </div>
</div>
<?php break; case 'dynamic_control': //动态控件 ?>

    <?= $this->renderPhpFile(
        __DIR__ . '/view.dynamic.control.php',
        [
            'controlOptions' => $control,
            'requiredStyle' => $requiredStyle,
            'groupField' => $groupField,
        ]) ?>
<?php break; case 'xselect': //xm-select普通扩展 ?>
<?php case 'xselect_tree': //xm-select下拉树扩展 ?>
<?php case 'xselect_remote': //xm-select远程搜索扩展 ?>
<?php case 'xselect_cascader': //xm-select级联模式 ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>">
    <?php if (!empty($control['label'])): ?>

    <span class="mb-1 label-color ym2-form-label">
        <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

            <sup class="layui-font-red">*</sup>
        <?php endif; ?>

        <?= $control['label'] ?>
        <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

            <span class="layui-font-gray f12">[ 选填 ]</span>
        <?php endif; ?>

        <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
    </span>
    <?php endif; ?>

    <!--xselect-->
    <div xm-select="<?= $control['__id'] ?>_options" ng-model="<?= $control['__scope'] ?>" id="<?= $control['__id'] ?>"<?= $control['attribute'] ?>></div>
</div>
<?php break; case 'star': //star 评分 ?>

<div class="form-group col-md-<?= $control['layout'] ?> <?= $control['class'] ?>">
    <?php if (!empty($control['label'])): ?>

        <label class="mb-1 label-color ym2-form-label" for="<?= $control['__id'] ?>">
            <?php if (!empty($control['required']) && $requiredStyle == 'mark'): ?>

                <sup class="layui-font-red">*</sup>
            <?php endif; ?>

            <?= $control['label'] ?>
            <?php if (empty($control['required']) && $requiredStyle == 'text'): ?>

                <span class="layui-font-gray f12">[ 选填 ]</span>
            <?php endif; ?>

            <comment class="layui-font-gray pl-1 f12"><?= $control['comment'] ?></comment>
        </label>
    <?php endif; ?>

    <!--star-->
    <div id="<?= $control['__id'] ?>"
         ym2-star="<?= $control['__id'] ?>_options"
         style="<?= $control['style'] ?>"
         class="ym2-form-control d-block"
         ng-model="<?= $control['__scope'] ?>"<?= $control['attribute'] ?>></div>
</div>
<?php break; endswitch; ?>
<?php endforeach; ?>
